<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: rgb(114, 20, 20);
            position: absolute;
            left: 5px;
            top: 5px;
        }
    </style>
</head>

<body>
    <script>
        onload = function() {
            var box = document.querySelector('.box');
            var top = 0;
            var left = 0;
            addEventListener('keypress', function(e) {
                if (e.key == "s") {
                    top += 5
                } else if (e.key == "w") {
                    top -= 5
                } else if (e.key == "a") {
                    left -= 5;
                } else if (e.key == 'd') {
                    left += 5;
                }
                box.style.top = top + "px"
                box.style.left = left + "px"
            })
        }
    </script>
    <div class="box"></div>

</body>

</html>